#plotting format
plotformat = theme(plot.title = element_text(face="bold",size = 17,hjust = 0.5),axis.title = element_text(face = "bold",size =15), axis.text.x = element_text(size=12), axis.title.y=element_text(size=14))+theme_bw()

theme_facet = function(base_size = 14, base_family = "Helvetica") {
  # Starts with theme_grey and then modify some parts
  theme_bw(base_size = base_size, base_family = base_family) %+replace%
    theme(
      strip.background = element_blank(),
      strip.text.x = element_text(size = 10),
      strip.text.y = element_text(size = 10),
      axis.text.x = element_blank(),
      axis.text.y = element_text(size=12,hjust=1),
      axis.ticks =  element_blank(), #element_line(colour = "black"), 
      axis.title.x= element_text(size=12),
      axis.title.y= element_text(size=12,angle=90),
      panel.background = element_blank(), 
      panel.border =element_blank(), 
      panel.grid.minor = element_blank(), 
      panel.spacing = unit(0.5, "lines"), 
      plot.background = element_blank(), 
      plot.margin = unit(c(0.3,  0.3, 0.3, 0.3), "lines"),
      axis.line.x = element_line(color="black", size = 0.5),
      axis.line.y = element_line(color="black", size = 0.5)
    )
}
#color
Features = c('#deebf7','#9ecae1','#6baed6','#4292c6','#08519c','#08306b',
             '#fee6ce','#fdae6b','#fd8d3c','#f16913','#a63603','#7f2704',
             '#f0f0f0','#bdbdbd','#969696','#737373','#252525','#000000',
             '#efedf5','#bcbddc','#9e9ac8','#807dba','#54278f','#3f007d')
dataPath = '/Volumes/Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/';

SameDifferent_fnames = list.files(path = dataPath,pattern = "SameDifferent")
Demo_fnames = list.files(path = dataPath,pattern = "demographics")

Load data

##specify variables
#for behavior information
completeFnames =list()
totalData = data.frame()
ic = 1;

#for demographic information
gender = data.frame()
age = data.frame()
ethnicity= data.frame()
race = data.frame()
subID = data.frame()

##
for (ifiles in 1:length(SameDifferent_fnames)){
  tempFile = read.table(paste0(dataPath,SameDifferent_fnames[ifiles]),header = F)
  Trials = unlist(strsplit(as.character(tempFile$V1), ";"))
  
  if (length(Trials)>10){
    keyNum = data.frame()
    accuracy = data.frame()
    feature_index = data.frame()
    RT = data.frame()
    Fir_img = data.frame()
    Sec_img = data.frame()
    for (i in 1:length(Trials)){
      temp = unlist(strsplit(Trials[i],","));
      keyNum = rbind(keyNum,as.numeric(temp[2]))
      accuracy = rbind(accuracy,as.numeric(temp[4]))
      RT = rbind(RT,as.numeric(temp[5]))
      feature_index = rbind(feature_index,as.numeric(temp[6]))
      Fir_img = rbind(Fir_img,as.numeric(temp[7]))
      Sec_img = rbind(Sec_img,as.numeric(temp[8]))
    }
    data = cbind(keyNum,accuracy,RT, feature_index,Fir_img,Sec_img)
    colnames(data) = c("keys","accuracy", "rt","feature_index", "Fimg","Simg")
    data = data[-1,]
    data$subID = ifiles;
    data$trialNum = 1:dim(data)[1];
    
    totalData = rbind(totalData,data)

    #subject ID for completing the tasks
    for (ifilesDe in 1:length(Demo_fnames)){
      if (unlist(strsplit(SameDifferent_fnames[ifiles],"SameDifferent"))[2]==unlist(strsplit(Demo_fnames[ifilesDe],"demographics"))[2]){
        tempDemoFile = read.table(paste0(dataPath,Demo_fnames[ifilesDe]),header = F)
        Demo_info = unlist(strsplit(as.character(tempDemoFile$V1), ";"))
        gender[ic,1] = unlist(Demo_info[1])
        age[ic,1]=unlist(Demo_info[2])
        ethnicity[ic,1]=unlist(Demo_info[3])
        race[ic,1]=unlist(Demo_info[4])
        subID[ic,1]=unlist(ifiles)
        }
    completeFnames[ic] =unlist(strsplit(SameDifferent_fnames[ifiles],"SameDifferent"))[2]}
    ic = ic+1;
  }else{
  }
}
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent1.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent30LSNF239UVW92XN4CFAEY3OE3F2IZ.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics30LSNF239UVW92XN4CFAEY3OE3F2IZ.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent31QNSG6A5RTA6XIG12KEX0QIMH2877.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics31QNSG6A5RTA6XIG12KEX0QIMH2877.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent31UV0MXWNQCO8ZGAMVH8C560YDE5IB.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics31UV0MXWNQCO8ZGAMVH8C560YDE5IB.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent33FOTY3KEMLY7ETRTYJAYCVO9TZC1A.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics33FOTY3KEMLY7ETRTYJAYCVO9TZC1A.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent33LK57MYLT5B9R3VYVI25BJI8AYSZ7.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics33LK57MYLT5B9R3VYVI25BJI8AYSZ7.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent34PGFRQONOBEGTF00EPHE6YDVMJJWO.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics34PGFRQONOBEGTF00EPHE6YDVMJJWO.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3570Y55XZPJ8EWKZ79M22QRDE56YG8.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3570Y55XZPJ8EWKZ79M22QRDE56YG8.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent35L9RVQFCOI5XJV5HE7VK5X1XFIUHB.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics35L9RVQFCOI5XJV5HE7VK5X1XFIUHB.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent369J354OFDA6VCAT1QRAJZ7KFTNG6W.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics369J354OFDA6VCAT1QRAJZ7KFTNG6W.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent37C0GNLMHF33JS02Z0Q2DE4N2XHD6L.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics37C0GNLMHF33JS02Z0Q2DE4N2XHD6L.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent37UEWGM5HT82DGIABV95N7UA9UT1RW.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics37UEWGM5HT82DGIABV95N7UA9UT1RW.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3907X2AHF05OQOKRH75UNV400ESP2A.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3907X2AHF05OQOKRH75UNV400ESP2A.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent39GAF6DQWR0U6NZRKFEFO4JDUXLV1S.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics39GAF6DQWR0U6NZRKFEFO4JDUXLV1S.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3D3VGR7TA0FYNJWPYZNOB09779OR3L.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3D3VGR7TA0FYNJWPYZNOB09779OR3L.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3DIP6YHAPCSVFCXQOAYK3AIZ8BIE8P.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3DIP6YHAPCSVFCXQOAYK3AIZ8BIE8P.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3DL65MZB8DFXRFN35MEP5WEIY06ECU.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3DL65MZB8DFXRFN35MEP5WEIY06ECU.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3DY46V3X3PICWBLVFBYENW2VTPI557.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3DY46V3X3PICWBLVFBYENW2VTPI557.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3EG49X351UCHHY5JQ0RE7L7FIH0X6I.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3EG49X351UCHHY5JQ0RE7L7FIH0X6I.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3EQHHY4HQSSAC8AFW7H5RTTKJ1NG5X.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3EQHHY4HQSSAC8AFW7H5RTTKJ1NG5X.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3FTOP5WARFOL83EF77WW7BP9UJ00J3.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3FTOP5WARFOL83EF77WW7BP9UJ00J3.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3H7XDTSHKCR4PRPZS84EHT6X3WKGW3.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3H7XDTSHKCR4PRPZS84EHT6X3WKGW3.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3IRIK4HM3AKTE0UOZ4VRT8M5HZ4C6N.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3IRIK4HM3AKTE0UOZ4VRT8M5HZ4C6N.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3M68NM076H7XK2J7H1LMI3LRH1L6R3.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3M68NM076H7XK2J7H1LMI3LRH1L6R3.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3MAOD8E57QAPOJBBPHDV9WT1DCMNXP.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3MAOD8E57QAPOJBBPHDV9WT1DCMNXP.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3QY5DC2MXRKLJN4ZMOJVHKLOHZRFUI.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3QY5DC2MXRKLJN4ZMOJVHKLOHZRFUI.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3RSDURM96AMAUIO81EWE2N611P4YE4.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3RSDURM96AMAUIO81EWE2N611P4YE4.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3TDXMTX3CBUKR3GORERD4BK0U5BI6K.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3TDXMTX3CBUKR3GORERD4BK0U5BI6K.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3TE3O85730892106UZ9JSQ4F106R22.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3TE3O85730892106UZ9JSQ4F106R22.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3U0SRXB7CD55RNPZGI73KE7DCUVNRL.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3U0SRXB7CD55RNPZGI73KE7DCUVNRL.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3U5NZHP4LR2S5EN90S81AZA2P0GPH4.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3U5NZHP4LR2S5EN90S81AZA2P0GPH4.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3WI0P0II61SW5BYMROT0O9VJYOJDRF.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3WI0P0II61SW5BYMROT0O9VJYOJDRF.txt'
## Warning in read.table(paste0(dataPath, SameDifferent_fnames[ifiles]),
## header = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## SameDifferent3Z4GS9HPNVA66JDXRXS8J0UNBZY77P.txt'
## Warning in read.table(paste0(dataPath, Demo_fnames[ifilesDe]), header
## = F): incomplete final line found by readTableHeader on '/Volumes/
## Macintosh HD/Users/Pam_sf_wang/Documents/AMTdata/Calibration_NewDesign_001/
## demographics3Z4GS9HPNVA66JDXRXS8J0UNBZY77P.txt'
demographic_information = cbind(gender,age,ethnicity,race,subID)
colnames(demographic_information) = c("Gender","Age","Ethnicity","Race","SubID")
demographic_information$Age = as.numeric(demographic_information$Age)

Identify and remove outliers

summarize = dplyr::summarize
#check basic performance -- remove non-responding subjects
temp = totalData %>% group_by(subID) %>% summarize(num_noresponses= sum(keys==-1), trialNum = length(subID))
sprintf("total trial number: %i; Number of subjects %i",temp$trialNum[1],dim(temp)[1])
## [1] "total trial number: 84; Number of subjects 33"
temp
## # A tibble: 33 x 3
##    subID num_noresponses trialNum
##    <int>           <int>    <int>
##  1     1               0       84
##  2     3               1       84
##  3     4               0       84
##  4     5               0       84
##  5     6               1       84
##  6     7               1       84
##  7     8               0       84
##  8     9               0       84
##  9    10               4       84
## 10    11               0       84
## # ... with 23 more rows
ggplot(temp, aes( y= num_noresponses, x= subID))+
  geom_point()+
  geom_hline(yintercept=42, linetype="dashed", color = "red", size=0.5)+
  labs(title="No responses", x ="subjuect ID", y = "number of no responses")+
  plotformat

#check feature number
tempFeature = totalData %>% group_by(subID) %>%summarize(feature = feature_index[1])
sprintf("Feature 1: %i; Feature 2: %i; Feature 3: %i",sum(tempFeature$feature==1),sum(tempFeature$feature==2),sum(tempFeature$feature==3))
## [1] "Feature 1: 10; Feature 2: 13; Feature 3: 10"
#no response subjects
removeSub = temp$subID[temp$num_noresponses>42]
totalData = totalData%>%filter(!subID %in% removeSub)
demographic_information = demographic_information%>%filter(!SubID %in%removeSub)

sprintf("remove subjects %i",length(removeSub))
## [1] "remove subjects 1"

Demographic information

genderCount = table(demographic_information$Gender)
EthnicityCount = table(demographic_information$Ethnicity)
RaceCount = table(demographic_information$Race)
genderCount
## 
##  F  M 
## 14 18
EthnicityCount
## 
## NHL 
##  32
RaceCount
## 
##  A AA  M  W 
##  2  2  3 25
summary(demographic_information$Age)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   26.00   29.00   31.00   31.44   34.25   36.00
ggplot(demographic_information, aes(demographic_information$Age)) + 
  geom_histogram()+
  geom_vline(xintercept=median(demographic_information$Age), linetype="dashed", color = "red", size=0.5)+
  #geom_vline(xintercept=mean(demographic_information$Age), linetype="dashed", color = "blue", size=0.5)+
  labs(title = "Age Distribution",x = "age", y = "counts")+
  plotformat
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Add conditions

summarize = dplyr::summarize
completeFnames = unlist(completeFnames)
#trial conditions: different:0; same:1 (same as keys)
totalData$cond = NA;
totalData$cond[totalData$Fimg==totalData$Simg]=1;
totalData$cond[totalData$Fimg!=totalData$Simg]=0;


totalData$level_diff = abs(totalData$Simg-totalData$Fimg);


#Assign pair identity (ignore order)
totalData$pairIdentity = NA;

totalData$pairIdentity[totalData$cond==1&totalData$Fimg==1]=1
totalData$pairIdentity[totalData$cond==1&totalData$Fimg==2]=2
totalData$pairIdentity[totalData$cond==1&totalData$Fimg==3]=3
totalData$pairIdentity[totalData$cond==1&totalData$Fimg==4]=4
totalData$pairIdentity[totalData$cond==1&totalData$Fimg==5]=5
totalData$pairIdentity[totalData$cond==1&totalData$Fimg==6]=6
totalData$pairIdentity[totalData$cond==1&totalData$Fimg==7]=7

totalData$pairIdentity[totalData$Fimg==1&totalData$Simg==2]=12
totalData$pairIdentity[totalData$Fimg==2&totalData$Simg==1]=12

totalData$pairIdentity[totalData$Fimg==1&totalData$Simg==3]=13
totalData$pairIdentity[totalData$Fimg==3&totalData$Simg==1]=13

totalData$pairIdentity[totalData$Fimg==1&totalData$Simg==4]=14
totalData$pairIdentity[totalData$Fimg==4&totalData$Simg==1]=14

totalData$pairIdentity[totalData$Fimg==1&totalData$Simg==5]=15
totalData$pairIdentity[totalData$Fimg==5&totalData$Simg==1]=15

totalData$pairIdentity[totalData$Fimg==1&totalData$Simg==6]=16
totalData$pairIdentity[totalData$Fimg==6&totalData$Simg==1]=16

totalData$pairIdentity[totalData$Fimg==1&totalData$Simg==7]=17
totalData$pairIdentity[totalData$Fimg==7&totalData$Simg==1]=17

totalData$pairIdentity[totalData$Fimg==2&totalData$Simg==3]=23
totalData$pairIdentity[totalData$Fimg==3&totalData$Simg==2]=23

totalData$pairIdentity[totalData$Fimg==2&totalData$Simg==4]=24
totalData$pairIdentity[totalData$Fimg==4&totalData$Simg==2]=24

totalData$pairIdentity[totalData$Fimg==2&totalData$Simg==5]=25
totalData$pairIdentity[totalData$Fimg==5&totalData$Simg==2]=25

totalData$pairIdentity[totalData$Fimg==2&totalData$Simg==6]=26
totalData$pairIdentity[totalData$Fimg==6&totalData$Simg==2]=26

totalData$pairIdentity[totalData$Fimg==2&totalData$Simg==7]=27
totalData$pairIdentity[totalData$Fimg==7&totalData$Simg==2]=27

totalData$pairIdentity[totalData$Fimg==3&totalData$Simg==4]=34
totalData$pairIdentity[totalData$Fimg==4&totalData$Simg==3]=34

totalData$pairIdentity[totalData$Fimg==3&totalData$Simg==5]=35
totalData$pairIdentity[totalData$Fimg==5&totalData$Simg==3]=35

totalData$pairIdentity[totalData$Fimg==3&totalData$Simg==6]=36
totalData$pairIdentity[totalData$Fimg==6&totalData$Simg==3]=36

totalData$pairIdentity[totalData$Fimg==3&totalData$Simg==7]=37
totalData$pairIdentity[totalData$Fimg==7&totalData$Simg==3]=37

totalData$pairIdentity[totalData$Fimg==4&totalData$Simg==5]=45
totalData$pairIdentity[totalData$Fimg==5&totalData$Simg==4]=45

totalData$pairIdentity[totalData$Fimg==4&totalData$Simg==6]=46
totalData$pairIdentity[totalData$Fimg==6&totalData$Simg==4]=46

totalData$pairIdentity[totalData$Fimg==4&totalData$Simg==7]=47
totalData$pairIdentity[totalData$Fimg==7&totalData$Simg==4]=47

totalData$pairIdentity[totalData$Fimg==5&totalData$Simg==6]=56
totalData$pairIdentity[totalData$Fimg==6&totalData$Simg==5]=56

totalData$pairIdentity[totalData$Fimg==5&totalData$Simg==7]=57
totalData$pairIdentity[totalData$Fimg==7&totalData$Simg==5]=57

totalData$pairIdentity[totalData$Fimg==6&totalData$Simg==7]=67
totalData$pairIdentity[totalData$Fimg==7&totalData$Simg==6]=67

totalData$pairIdentity = as.factor(totalData$pairIdentity)
summarize = dplyr::summarize
#Times
TimesRT = totalData %>% group_by(subID,pairIdentity,feature_index,cond)%>%summarize(Frt = rt[1],Srt = rt[2], Trt = rt[3], Ftrial = trialNum[1],Strial = trialNum[2],Ttrial = trialNum[3])

TimesRT_long = gather(TimesRT, response_type, number_resp,Frt,Srt,Trt)
ggplot(subset(TimesRT_long, cond==1), aes(x = pairIdentity, y = number_resp, group = pairIdentity, color = as.factor(pairIdentity)))+
  geom_boxplot(fill = "white",lwd = 1)+
  geom_jitter(width=0.2,alpha = 0.5)+
  ylim(0,2500)+
  facet_wrap(response_type~feature_index)+
  labs(title="Same", x = "level", y = "RT")+
  plotformat
## Warning: Removed 6 rows containing missing values (geom_point).

ggplot(subset(TimesRT_long, cond==0), aes(x = pairIdentity, y = number_resp, group = pairIdentity, color = as.factor(pairIdentity)))+
  geom_boxplot(fill = "white",lwd = 1)+
  geom_jitter(width=0.2,alpha = 0.5)+
  facet_wrap(response_type~feature_index)+
  labs(title="Different", x = "Same level", y = "RT")+
  plotformat

TimesRTcorrect = totalData %>% group_by(subID,pairIdentity,feature_index,cond)%>%filter(accuracy==1) %>%summarize(Frt = rt[1],Srt = rt[2], Trt = rt[3], Ftrial = trialNum[1],Strial = trialNum[2],Ttrial = trialNum[3])

TimesRTcorrect_long = gather(TimesRTcorrect, response_type, number_resp,Frt,Srt,Trt)
ggplot(subset(TimesRTcorrect_long, cond==1), aes(x = pairIdentity, y = number_resp, group = pairIdentity, color = as.factor(pairIdentity)))+
  geom_boxplot(fill = "white",lwd = 1)+
  geom_jitter(width=0.2,alpha = 0.5)+
  facet_wrap(response_type~feature_index)+
  labs(title="Correct same", x = "Same level", y = "RT")+
  plotformat
## Warning: Removed 174 rows containing non-finite values (stat_boxplot).
## Warning: Removed 174 rows containing missing values (geom_point).

ggplot(subset(TimesRTcorrect_long, cond==0), aes(x = pairIdentity, y = number_resp, group = pairIdentity, color = as.factor(pairIdentity)))+
  geom_boxplot(fill = "white",lwd = 1)+
  geom_jitter(width=0.2,alpha = 0.5)+
  facet_wrap(response_type~feature_index,strip.position = 'bottom')+
  labs(title="Correct different", x = "Same level", y = "RT")+
  theme_facet()
## Warning: Removed 471 rows containing non-finite values (stat_boxplot).
## Warning: Removed 471 rows containing missing values (geom_point).

Behavior analysis

summarize = dplyr::summarize
basic = totalData %>% filter(keys>=0)%>% group_by(subID)%>% summarize(num_noresposnes = sum(keys==-1), num_same_resp = sum(keys==1), num_diff_resp = sum(keys==0), num_same_trials =sum(cond==1), num_diff_trials = sum(cond==0), 
                                                    hit = sum(keys==1&cond==1), 
                                                    fa= sum(keys==1&cond==0), 
                                                    cr = sum(keys==0&cond==0),
                                                    miss = sum(keys==0&cond==1),
                                                    HitRate =sum(keys==1&cond==1)/sum(cond==1), 
                                                    FARate = sum(keys==1&cond==0)/sum(cond==0), 
                                                    CRRate = sum(keys==0&cond==0)/sum(cond==0),
                                                    MissRate = sum(keys==0&cond==1)/sum(cond==1), 
                                                    d_p = qnorm(HitRate)-qnorm(FARate))
basic
## # A tibble: 32 x 15
##    subID num_noresposnes num_same_resp num_diff_resp num_same_trials
##    <int>           <int>         <int>         <int>           <int>
##  1     1               0            26            58              21
##  2     3               0            10            73              20
##  3     4               0            21            63              21
##  4     5               0            21            63              21
##  5     6               0            22            61              20
##  6     7               0            37            46              20
##  7     8               0            27            57              21
##  8     9               0            37            47              21
##  9    10               0            31            49              19
## 10    11               0            32            52              21
## # ... with 22 more rows, and 10 more variables: num_diff_trials <int>,
## #   hit <int>, fa <int>, cr <int>, miss <int>, HitRate <dbl>,
## #   FARate <dbl>, CRRate <dbl>, MissRate <dbl>, d_p <dbl>
#plotting
basic_longform = gather(basic, response_type, number_resp, HitRate,FARate,CRRate,MissRate)
head(basic_longform)
## # A tibble: 6 x 13
##   subID num_noresposnes num_same_resp num_diff_resp num_same_trials
##   <int>           <int>         <int>         <int>           <int>
## 1     1               0            26            58              21
## 2     3               0            10            73              20
## 3     4               0            21            63              21
## 4     5               0            21            63              21
## 5     6               0            22            61              20
## 6     7               0            37            46              20
## # ... with 8 more variables: num_diff_trials <int>, hit <int>, fa <int>,
## #   cr <int>, miss <int>, d_p <dbl>, response_type <chr>,
## #   number_resp <dbl>
ggplot(basic_longform, aes(x = response_type, y = number_resp, color = response_type))+
  geom_boxplot(fill = "white",lwd = 1)+
  geom_jitter(width=0.2,alpha = 0.5)+
  labs(title="Proportaion response type", x = "response type", y = "proportion")+
  plotformat

##########
basicFeature = totalData %>% filter(keys>=0)%>% group_by(subID,feature_index)%>% summarize(num_noresposnes = sum(keys==-1), num_same_resp = sum(keys==1), num_diff_resp = sum(keys==0), num_same_trials =sum(cond==1), num_diff_trials = sum(cond==0), 
                                                    hit = sum(keys==1&cond==1), 
                                                    fa= sum(keys==1&cond==0), 
                                                    cr = sum(keys==0&cond==0),
                                                    miss = sum(keys==0&cond==1),
                                                    HitRate =sum(keys==1&cond==1)/sum(cond==1), 
                                                    FARate = sum(keys==1&cond==0)/sum(cond==0), 
                                                    CRRate = sum(keys==0&cond==0)/sum(cond==0),
                                                    MissRate = sum(keys==0&cond==1)/sum(cond==1), 
                                                    d_p = qnorm(HitRate)-qnorm(FARate))
basicFeature_longform = gather(basicFeature, response_type, number_resp, HitRate,FARate,CRRate,MissRate)
head(basicFeature_longform)
## # A tibble: 6 x 14
## # Groups:   subID [6]
##   subID feature_index num_noresposnes num_same_resp num_diff_resp
##   <int>         <dbl>           <int>         <int>         <int>
## 1     1             3               0            26            58
## 2     3             3               0            10            73
## 3     4             1               0            21            63
## 4     5             3               0            21            63
## 5     6             1               0            22            61
## 6     7             2               0            37            46
## # ... with 9 more variables: num_same_trials <int>, num_diff_trials <int>,
## #   hit <int>, fa <int>, cr <int>, miss <int>, d_p <dbl>,
## #   response_type <chr>, number_resp <dbl>
ggplot(basicFeature_longform, aes(x = response_type, y = number_resp, color = response_type))+
  geom_boxplot(fill = "white",lwd = 1)+
  geom_jitter(width=0.2,alpha = 0.5)+
  facet_wrap(~feature_index)+
  labs(title="Proportaion response type by feature", x = "response type", y = "proportion")+
  plotformat

###########
basicLevel = totalData %>% filter(keys>=0)%>% group_by(subID,level_diff)%>% summarize(num_noresposnes = sum(keys==-1), num_same_resp = sum(keys==1), num_diff_resp = sum(keys==0), num_same_trials =sum(cond==1), num_diff_trials = sum(cond==0), 
                                                    hit = sum(keys==1&cond==1), 
                                                    fa= sum(keys==1&cond==0), 
                                                    cr = sum(keys==0&cond==0),
                                                    miss = sum(keys==0&cond==1),
                                                    HitRate =sum(keys==1&cond==1)/sum(cond==1), 
                                                    FARate = sum(keys==1&cond==0)/sum(cond==0), 
                                                    CRRate = sum(keys==0&cond==0)/sum(cond==0),
                                                    MissRate = sum(keys==0&cond==1)/sum(cond==1), 
                                                    d_p = qnorm(HitRate)-qnorm(FARate))
basicLevel_longform = gather(basicLevel, response_type, number_resp, HitRate,FARate,CRRate,MissRate)
head(basicLevel_longform)
## # A tibble: 6 x 14
## # Groups:   subID [1]
##   subID level_diff num_noresposnes num_same_resp num_diff_resp
##   <int>      <dbl>           <int>         <int>         <int>
## 1     1          0               0            10            11
## 2     1          1               0             7            11
## 3     1          2               0             3            12
## 4     1          3               0             3             9
## 5     1          4               0             3             6
## 6     1          5               0             0             6
## # ... with 9 more variables: num_same_trials <int>, num_diff_trials <int>,
## #   hit <int>, fa <int>, cr <int>, miss <int>, d_p <dbl>,
## #   response_type <chr>, number_resp <dbl>
ggplot(basicLevel_longform, aes(x = response_type, y = number_resp, color = response_type))+
  geom_boxplot(fill = "white",lwd = 1)+
  geom_jitter(width=0.2,alpha = 0.5)+
  facet_wrap(~level_diff,nrow = 1)+
  labs(title="Proportaion response type by difficulty level", x = "response type", y = "proportion")+
  theme_facet()
## Warning: Removed 448 rows containing non-finite values (stat_boxplot).
## Warning: Removed 448 rows containing missing values (geom_point).

###########
basicLevelFeature = totalData %>% filter(keys>=0)%>% group_by(subID,level_diff,feature_index)%>% summarize(num_noresposnes = sum(keys==-1), num_same_resp = sum(keys==1), num_diff_resp = sum(keys==0), num_same_trials =sum(cond==1), num_diff_trials = sum(cond==0), 
                                                    hit = sum(keys==1&cond==1), 
                                                    fa= sum(keys==1&cond==0), 
                                                    cr = sum(keys==0&cond==0),
                                                    miss = sum(keys==0&cond==1),
                                                    HitRate =sum(keys==1&cond==1)/sum(cond==1), 
                                                    FARate = sum(keys==1&cond==0)/sum(cond==0), 
                                                    CRRate = sum(keys==0&cond==0)/sum(cond==0),
                                                    MissRate = sum(keys==0&cond==1)/sum(cond==1), 
                                                    d_p = qnorm(HitRate)-qnorm(FARate))
basicLevelFeature_longform = gather(basicLevelFeature, response_type, number_resp, HitRate,FARate,CRRate,MissRate)
head(basicLevelFeature_longform)
## # A tibble: 6 x 15
## # Groups:   subID, level_diff [6]
##   subID level_diff feature_index num_noresposnes num_same_resp
##   <int>      <dbl>         <dbl>           <int>         <int>
## 1     1          0             3               0            10
## 2     1          1             3               0             7
## 3     1          2             3               0             3
## 4     1          3             3               0             3
## 5     1          4             3               0             3
## 6     1          5             3               0             0
## # ... with 10 more variables: num_diff_resp <int>, num_same_trials <int>,
## #   num_diff_trials <int>, hit <int>, fa <int>, cr <int>, miss <int>,
## #   d_p <dbl>, response_type <chr>, number_resp <dbl>
ggplot(basicLevelFeature_longform, aes(x = response_type, y = number_resp, color = response_type))+
  geom_boxplot(fill = "white",lwd = 1)+
  geom_jitter(width=0.2,alpha = 0.5)+
  facet_wrap(feature_index~level_diff,nrow = 3,strip.position = "bottom")+
  labs(title="Proportaion response type by difficulty level", x = "level diff", y = "proportion")+
  theme_facet()
## Warning: Removed 448 rows containing non-finite values (stat_boxplot).

## Warning: Removed 448 rows containing missing values (geom_point).

reaction time and difficulty levels

summarize = dplyr::summarize
responseData = totalData %>%filter(keys>=0,accuracy==1)
ggplot(responseData, aes(x = level_diff, y = rt, group = as.factor(level_diff), color = as.factor(level_diff)))+
   geom_boxplot(fill = "white",lwd = 1)+
  geom_jitter(width=0.2,alpha = 0.5)+
  facet_wrap(~feature_index)+
    ylim(0,2500)+
  labs(title="Reaction type by difficulty levels", x = "response type", y = "RT (ms)")+
  plotformat

responseData_firstHalf = totalData %>%filter(keys>=0,accuracy==1,trialNum<42)
ggplot(responseData_firstHalf, aes(x = level_diff, y = rt, group = as.factor(level_diff), color = as.factor(level_diff)))+
   geom_boxplot(fill = "white",lwd = 1)+
  geom_jitter(width=0.2,alpha = 0.5)+
  facet_wrap(~feature_index)+
    ylim(0,2500)+
  labs(title="Reaction type by difficulty levels -first", x = "response type", y = "RT (ms)")+
  plotformat

responseData_lastHalf = totalData %>%filter(keys>=0,accuracy==1,trialNum>42)
ggplot(responseData_lastHalf, aes(x = level_diff, y = rt, group = as.factor(level_diff), color = as.factor(level_diff)))+
   geom_boxplot(fill = "white",lwd = 1)+
  geom_jitter(width=0.2,alpha = 0.5)+
  facet_wrap(~feature_index)+
  ylim(0,2500)+
  labs(title="Reaction type by difficulty levels -last", x = "response type", y = "RT (ms)")+
  plotformat

#temp = responseData %>% group_by(subID, level_diff, feature_index) %>%summarise(mean_RT = mean(rt))
#ggplot(temp,aes(x = level_diff, y = mean_RT, group = level_diff))+
#  geom_boxplot(fill = "white",lwd = 1)+
#  geom_jitter(width=0.2,alpha = 0.5)+
#  facet_wrap(~feature_index)+
#  labs(title="Proportaion response type", x = "response type", y = "RT (ms)")+
#  plotformat

accuracy and difficulty levels

accuracyData = totalData %>%filter(keys>=0)%>%group_by(subID,feature_index,level_diff)%>%summarize(meanAccuracy = sum(accuracy==1)/length(subID))
ggplot(accuracyData, aes(x = level_diff, y = meanAccuracy, group = as.factor(level_diff), color = as.factor(level_diff)))+
   geom_boxplot(fill = "white",lwd = 1)+
  geom_jitter(width=0.2,alpha = 0.5)+
  facet_wrap(~feature_index)+
  labs(title="Accuracy by difficulty levels", x = "difficulty level", y = "proportion correct")+
  plotformat

accuracy and pair

accuracyDataPairSame = totalData %>%filter(keys>=0,cond==1)%>%group_by(subID,feature_index,pairIdentity)%>%summarize(propAccuracy = sum(accuracy==1)/length(subID))

ggplot(accuracyDataPairSame, aes(x = pairIdentity, y = propAccuracy, group = as.factor(pairIdentity), color = as.factor(pairIdentity)))+
  geom_boxplot(fill = "white",lwd = 1)+
  geom_point(alpha = 0.5)+
  #geom_jitter(width=0.05,alpha = 0.5)+
  facet_wrap(~feature_index)+
  labs(title="Accuracy by same pairs", x = "difficulty level", y = "proportion correct")+
  plotformat

accuracyDataPairDiff = totalData %>%filter(keys>=0,cond==0)%>%group_by(subID,feature_index,pairIdentity)%>%summarize(propAccuracy = sum(accuracy==1)/length(subID))
ggplot(accuracyDataPairDiff, aes(x = as.factor(pairIdentity), y = propAccuracy, group = as.factor(pairIdentity), color = as.factor(pairIdentity)))+
  geom_boxplot(fill = "white",lwd = 1)+
  geom_point(alpha = 0.5)+
  #geom_jitter(width=0.2,alpha = 0.5)+
  facet_wrap(~feature_index)+
  labs(title="Accuracy by same pairs", x = "difficulty level", y = "proportion correct")+
  plotformat